package jianj.jianj.app.widght

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import androidx.viewpager2.widget.ViewPager2
import com.lalifa.extension.pageChangedListener
import com.lalifa.googledate.R
import com.lalifa.googledate.ui.adapter.emojiAdapter2
import com.lalifa.googledate.widget.pageAdapter.CircleIndicator

class EmojiView1(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) {
    private val mRootView: View =
        LayoutInflater.from(getContext()).inflate(R.layout.emoji_layout2, this)
    private var callBack: (Int, String) -> Unit = { _, _ -> }

    init {
        initView()
    }

    private fun initView() {
        val viewpager = mRootView.findViewById<ViewPager2>(R.id.view_pager)
        val llIndicator = mRootView.findViewById<LinearLayout>(R.id.ll_indicator)
        val circleIndicator = CircleIndicator(context)
        llIndicator.addView(circleIndicator)
        val list2 = resources.getStringArray(R.array.color_list).toList()
        val data = list2.windowed(size = 10, step = 10, partialWindows = false).toList()
        viewpager.emojiAdapter2(true,{ type, s ->
            callBack.invoke(type, s)
        }) {
            models = data
        }.pageChangedListener {
            circleIndicator.onPageSelected(it)
        }
        circleIndicator.onPageChanged(data.size, 0)

    }

    fun setOnEmojiClickListener(clickListener: (Int, String) -> Unit) {
        callBack = clickListener
    }
}